//
//  XGL_LiveRoomChatTableViewCell.swift
//  XGamesLive
//
//  Created by ios on 2024/5/30.
//

import UIKit

class XGL_LiveRoomChatTableViewCell: UITableViewCell {
    
    var itemHeaderView: UserHeadView!
    var itemNameText: UILabel!
    var itemContentText: UILabel!
    
    var itemData: PublishCommentData = PublishCommentData(){
        didSet{
            if let infor = itemData.auditUserExt{
                self.itemHeaderView.userData = infor
                self.itemNameText.text = infor.data1
            }
            self.itemContentText.text = self.itemData.data8
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .clear
        self.contentView.backgroundColor = .clear
        self.selectionStyle = .none
        self.createItemView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func createItemView(){
        let cardContentView = UIView().then { make in
            make.backgroundColor = UIColor.black.withAlphaComponent(0.4)
            make.layerCornerRadius = 12.0
            make.setContentHuggingPriority(700, for: .horizontal)
            make.setContentCompressionResistancePriority(680, for: .horizontal)
        }
        self.itemHeaderView = UserHeadView().then({ make in
            make.layerCornerRadius = 13.0
            make.clipsToBounds = true
        })
        self.itemNameText = UILabel().then({ make in
            make.textColor = UIColor.hexColor("#80FFE6")
            make.font = UIFont.pingfangSC_Regular(fontSize: 14.0)
        })
        self.itemContentText = UILabel().then({ make in
            make.textColor = UIColor.white
            make.font = UIFont.pingfangSC_Regular(fontSize: 16.0)
            make.numberOfLines = 0
            make.lineBreakMode = .byWordWrapping
        })
        let line = UIView()
        cardContentView.addSubviews([self.itemHeaderView,itemNameText,self.itemContentText])
        self.contentView.addSubviews([cardContentView,line])
        itemHeaderView.snp.makeConstraints { make in
            make.top.left.equalTo(10.0)
            make.width.height.equalTo(26.0)
        }
        itemNameText.snp.makeConstraints { make in
            make.left.equalTo(itemHeaderView.snp.right).offset(10.0)
            make.centerY.equalTo(itemHeaderView)
            make.right.equalTo(-10.0)
        }
        itemContentText.snp.makeConstraints { make in
            make.right.equalTo(-16.0)
            make.top.equalTo(itemHeaderView.snp.bottom).offset(1.0)
            make.left.equalTo(itemNameText)
        }
        cardContentView.snp.makeConstraints { make in
            make.left.equalTo(15.0)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
            make.right.equalTo(-15.0).priority(690)
            make.bottom.equalTo(itemContentText.snp.bottom).offset(12.0)
        }
        line.snp.makeConstraints { make in
            make.centerX.width.bottom.equalToSuperview()
            make.height.equalTo(0).priority(.high)
            make.top.equalTo(cardContentView.snp.bottom).offset(20.0)
        }
    }
}
